﻿Public Class DRUGDOSAGE

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub DRUGDOSAGE_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SelectDatagridMASDRGDOSAGE()

        DesignForm(Me)
        DesignGrid(MASDRGDOSAGEGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridMASDRGDOSAGE()
        Dim objSelectDataMASDRGDOSAGE As New masdrgdosage
        Dim MASDRGDOSAGE As DataTable
        MASDRGDOSAGE = connect.GetTable(objSelectDataMASDRGDOSAGE.selectMasdrgdosage_)
        MASDRGDOSAGEGrid.PrimaryGrid.DataSource = MASDRGDOSAGE
    End Sub

    Private Sub MASDRGDOSAGEGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles MASDRGDOSAGEGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสรูปแบบยา").Value() IsNot DBNull.Value Then
            DFORMtxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสรูปแบบยา").Value()
        Else
            DFORMtxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รูปแบบยา").Value() IsNot DBNull.Value Then
            DOSAGEFORMTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รูปแบบยา").Value()
        Else
            DOSAGEFORMTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("code รูปแบบยา").Value() IsNot DBNull.Value Then
            DOSAGECODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("code รูปแบบยา").Value()
        Else
            DOSAGECODETxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            masdrgdosageStatusChk.Checked = True
        Else
            masdrgdosageStatusChk.Checked = False
        End If
        connect = CONDB.NewConnection()
        If e.GridCell.GridColumn.Name = "สถานะการเปิดใช้งาน" Then
            Try
                Dim Sql As String
                connect.BeginTrans()
                Sql = "UPDATE masdrgdosage SET "
                If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then
                    Sql += "`status` = 1 "
                Else
                    Sql += "`status` = 0 "
                End If
                Sql += "WHERE `dform` = '" & DFORMtxt.Text & "' ;"

                connect.ExecuteNonQuery(Sql)
                connect.CommitTrans()
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            End Try
        End If
        connect.Dispose()
        addMasdrgdosage.Enabled = False
    End Sub

    Private Sub addMasdrgdosage_Click(sender As Object, e As EventArgs) Handles addMasdrgdosage.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If DOSAGEFORMTxt.Text.ToString.Length > 0 Then
                    Dim objInsertData As New masdrgdosage
                    objInsertData.DOSAGEFORM_ = DOSAGEFORMTxt.Text
                    objInsertData.CODE_ = DOSAGECODETxt.Text
                    objInsertData.STATUS_ = masdrgdosageStatusChk.Checked
                    objInsertData.insertMasdrgdosageData()

                    SelectDatagridMASDRGDOSAGE()

                    DFORMtxt.Text = ""
                    DOSAGEFORMTxt.Text = ""
                    DOSAGECODETxt.Text = ""
                    masdrgdosageStatusChk.Checked = False
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editMasdrgdosage_Click(sender As Object, e As EventArgs) Handles editMasdrgdosage.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If DFORMtxt.Text.ToString.Length > 0 And DOSAGEFORMTxt.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลรูปแบบของยาดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New masdrgdosage
                        objEditData.DFORM_ = DFORMtxt.Text
                        objEditData.DOSAGEFORM_ = DOSAGEFORMTxt.Text
                        objEditData.CODE_ = DOSAGECODETxt.Text
                        objEditData.STATUS_ = masdrgdosageStatusChk.Checked
                        objEditData.editMasdrgdosageData()

                        SelectDatagridMASDRGDOSAGE()

                        DFORMtxt.Text = ""
                        DOSAGEFORMTxt.Text = ""
                        DOSAGECODETxt.Text = ""
                        masdrgdosageStatusChk.Checked = False
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
                addMasdrgdosage.Enabled = True
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("masdrgdosage")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("masdrgdosage")
        nextform.ShowDialog()
    End Sub
End Class